<?php

namespace common\models\wechat;

use common\models\wechat\WechatReplyKeywordQuery;
use Yii;
use yii\behaviors\TimestampBehavior;

/**
 * This is the model class for table "wechat_reply_keyword".
 *
 * @property string $id
 * @property string $rid
 * @property string $uniacid
 * @property string $module
 * @property string $content
 * @property integer $type
 * @property integer $displayorder
 * @property integer $status
 */
class WechatReplyKeyword extends \yii\db\ActiveRecord
{

    //主要用于日志记录
    public $uselog = [
        'tabcomment' => '关键字',      //用于修改了什么的显示
        'mainfield' => 'content',      //主要的显示标题的字段
        'picturefield' => [],        //图片字段
        'timefield' => [],       //时间字段
        'unsetfiled' =>[],      //不需要记录的字段
    ];

    /**
     * text类型请求 直接匹配关键字
     */
    const TYPE_MATCH = 1;
    /**
     * text类型请求 正则表达式
     */
    const TYPE_INCLUDE = 2;
    /**
     * text类型请求 包含关键字
     */
    const TYPE_REGULAR = 3;


    /**
     * text类型请求 正则表达式
     */
    const TYPE_NEWS = 'news';


    /**
     * image类型请求
     */
    const TYPE_IMAGE = 'image';
    /**
     * 语音类型请求
     */
    const TYPE_VOICE = 'voice';

    /**
     * 语音类型请求
     */
    const TYPE_MUSIC = 'music';
    /**
     * 视频类型请求
     */
    const TYPE_VIDEO = 'video';
    /**
     * 短视频类型请求
     */
    const TYPE_SHORT_VIDEO = 'short_video';
    /**
     * 位置类型请求
     */
    const TYPE_LOCATION = 'location';
    /**
     * 链接类型请求
     */
    const TYPE_LINK = 'link';
    /**
     * 关注请求
     */
    const TYPE_SUBSCRIBE = 'subscribe';
    /**
     * 取消关注请求
     */
    const TYPE_UNSUBSCRIBE = 'unsubscribe';


    /**
     * 触发类型
     * @var array
     */
    public static $types = [
        self::TYPE_MATCH => '直接匹配关键字',
        self::TYPE_REGULAR => '正则匹配关键字',
        self::TYPE_INCLUDE => '包含关键字',

        self::TYPE_IMAGE => '图片请求',
        self::TYPE_VOICE => '语音请求',
        self::TYPE_VIDEO => '视频请求',
        self::TYPE_MUSIC => '音乐请求',
        self::TYPE_SHORT_VIDEO => '段视频请求',
        self::TYPE_LOCATION => '位置请求',
        self::TYPE_LINK => '链接请求',

        self::TYPE_SUBSCRIBE => '关注请求',
        self::TYPE_UNSUBSCRIBE => '取消关注请求',
    ];



    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'wechat_reply_keyword';
    }


    public static function find()
    {
        return Yii::createObject(WechatReplyKeywordQuery::className(), [get_called_class()]);
    }


    public function behaviors()
    {
        return [
            'timestamp' => TimestampBehavior::className()
        ];
    }



    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['rid', 'wid', 'module', 'content', 'type'], 'required'],
            [['rid', 'wid', 'type', 'displayorder', 'status','start_at','end_at','created_at','updated_at'], 'integer'],
            [['module'], 'string', 'max' => 50],
            [['content','matchtype'], 'string', 'max' => 255],
            [['id','displayorder','status','start_at','end_at'], 'safe'],

        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'rid' => '规则id',
            'wid' => '公众号id',
            'module' => '模块',
            'content' => '关键字',
            'type' => '触发类型',
            'displayorder' => '排序',
            'status' => '状态',
            'matchtype' => '匹配类型',
        ];
    }


    //关联rule
    public function getRule()
    {
        return $this->hasOne(WechatReplyRule::className(),['id'=>'rid']);
    }






}
